<template>
  <lay-layout class="Pop">
 
  
   
 
   <lay-body  >
     <lay-form :model="model" ref="layFormRef" class="MainForm" >       
      

<lay-form-item label="排序号" prop="sortno" required >
<lay-input-number v-model="model.sortno" :step="1" position="right"></lay-input-number>
</lay-form-item>      
      
<lay-form-item label="名称" prop="name" required>
<lay-input v-model="model.name" placeholder=""></lay-input>
</lay-form-item>

<lay-form-item label="自动启动" prop="autoStart" >
<lay-switch v-model="model.autoStart" ></lay-switch> 
  </lay-form-item>

<lay-form-item label="启动类型" prop="lx" required>
  <lay-select v-model="model.lx" :items="lxItems"
    placeholder="请选择"
    @change="lxChange">             
          </lay-select>
</lay-form-item>

<lay-form-item :label="titleDataSource.startInfo" prop="startInfo" >
<lay-input v-model="model.startInfo" 
  placeholder="程序完整路径或服务名称"></lay-input>
</lay-form-item>


<lay-form-item label="启动参数" prop="startArguments" >
<lay-input v-model="model.startArguments" 
  placeholder="启动参数"></lay-input>
</lay-form-item>


<lay-form-item label="工作路径" prop="startDir" >
<lay-input v-model="model.startDir" 
  placeholder="工作路径"></lay-input>
</lay-form-item>


<lay-form-item label="启动等待" prop="startWaitMs" required>
<lay-input-number v-model="model.startWaitMs" :step="1" position="right"></lay-input-number>
</lay-form-item>

<lay-form-item label="检查方法" prop="ckMethod" >
  <lay-select v-model="model.ckMethod" :items="ckMethodItems" 
  placeholder="请选择"
  @change="ckMethodChange">
          </lay-select>
</lay-form-item>

<lay-form-item :label="titleDataSource.ckArg1" prop="ckArg1" >
<lay-input v-model="model.ckArg1" placeholder="参数1"></lay-input>
</lay-form-item>

<lay-form-item :label="titleDataSource.ckArg2" prop="ckArg2" >
<lay-input v-model="model.ckArg2" placeholder="参数2"></lay-input>
</lay-form-item>

<lay-form-item :label="titleDataSource.ckArg3" prop="ckArg3" >
<lay-input v-model="model.ckArg3" placeholder="参数3"></lay-input>
</lay-form-item>

<lay-form-item :label="titleDataSource.ckArg4" prop="ckArg4" >
<lay-input v-model="model.ckArg4" placeholder="参数4"></lay-input>
</lay-form-item>

<lay-form-item label="检查间隔" prop="ckInterval" >
<lay-input-number v-model="model.ckInterval" :step="1" position="right"></lay-input-number>
</lay-form-item>

<lay-form-item label="重启次数" prop="ckFailRestar" >
<lay-input-number v-model="model.ckFailRestar" :step="1" 
position="right"
aria-placeholder="失败几次重启"
></lay-input-number>
</lay-form-item>

<lay-form-item label="短信次数" prop="ckFailSms" >
<lay-input-number v-model="model.ckFailSms"
 :step="1" position="right"
 aria-placeholder="失败几次发送短信"
 ></lay-input-number>
</lay-form-item>


 
           </lay-form>
     </lay-body>
 
 
 
     <lay-footer>
      
       <lay-button size="sm" type="primary" @click="toSubmit"
             >保存</lay-button
           >
           <lay-button size="sm" @click="toCancel" style="margin-left:40px;">取消</lay-button>
     </lay-footer>
   </lay-layout>
 
 </template>
 
 <script lang="ts">
 import { ref, watch,reactive,onMounted,h } from 'vue'
 import { layer } from '@layui/layer-vue'
 import MyHttp from "../../library/MyHttp";  
 import MyWin from "../../library/MyWin"; 
 import MyPage from "../../library/MyPage"; 
 import {MyExcel} from "../../library/MyExcel"; 
 import {MySimpleExport,TableColumn} from "../../library/MySimpleExport"; 
 import MyData from "../../library/MyData";  
  
 
 export default {
   props:{
       data:Object,
       isAdd:Boolean
   },
  
 
   setup(prop:any, context:any) {
     const baseUrl="/htsoft";
     const myWin=ref<any>(null);
     const model = reactive<any>(prop.data )
     const layFormRef = ref<any>()     
     const toSubmit=async()=>{
       layFormRef.value.validate((isValidate:boolean, model:any, errors:Array<any>) => {
           if(!isValidate){
             let msg='';
             errors.forEach(element=>{ 
               msg+=`${element.message}
               `; 
             })
             
             MyWin.alert(msg,{});
             return;
           }
           
           
 
           save();
       });
     } 
     const toCancel=()=>{ 
       context.emit("cancel");  
       myWin.value.close();
     }
     const save=async()=>{
       let url=baseUrl+"/Insert";
       if(!prop.isAdd){
         url=baseUrl+"/update";
       }
       var r=await new MyHttp().post(url,model,
         { 
         }
       ); 
       context.emit("ok",model); 
       myWin.value.close();  
     }
 
  
    const titleDataSource=reactive<any>({
      startInfo:"启动信息",
      ckArg1:"启动参数1",
      ckArg2:"启动参数2",
      ckArg3:"启动参数3",
      ckArg4:"启动参数4",
    });
    const lxChange=()=>{
      switch(model.lx){
        case "Exe":
          titleDataSource.startInfo="Exe完整路径"
          break;
        case "Svr":
          titleDataSource.startInfo="服务名称"
          break;
        default:
        titleDataSource.startInfo=""
          break;
      }
    }
    const ckMethodChange=()=>{
      switch(model.ckMethod){
        case "Http":
          titleDataSource.ckArg1="Url完整路径"
          break;
        case "Redis":
          titleDataSource.ckArg1="连接字符串";
          titleDataSource.ckArg2="Redis Key";
          break;
        case "SqlServer":
          titleDataSource.ckArg1="连接字符串";
          titleDataSource.ckArg2="运行Sql";
          break;
        case "MySql":
          titleDataSource.ckArg1="连接字符串";
          titleDataSource.ckArg2="运行Sql";
          break;
        default:
          titleDataSource.ckArg1="检查参数1";
          titleDataSource.ckArg2="检查参数2";
          titleDataSource.ckArg3="检查参数3";
          titleDataSource.ckArg4="检查参数4";

          break;
      } 
    }
     onMounted(() =>{  
       
       myWin.value=new MyWin();
       lxChange();
       ckMethodChange();
     });
 
     const lxItems=ref([
       {label:'程序', value:"Exe"},
       {label:'服务', value:"Svr"},
       {label:'其他', value:"Other"},
     ])
 
 
     const ckMethodItems=ref([
       {label:'http', value:"Http"},
       {label:'redis', value:"Redis"},
       {label:'sqlserver', value:"SqlServer"},
       {label:'mysql', value:"MySql"},
       {label:'other', value:"other"},
     ])
 
  
 
 
     return {
       model,
       layFormRef,
       toSubmit,
       toCancel, 
       lxItems,
       ckMethodItems,

       lxChange,
       ckMethodChange,
       titleDataSource, 

     }
   }
 }
 </script>
 <style scoped>
 .Pop .layui-footer,
 .Pop .layui-header {
   height: 50px;
   text-align: center; 
   padding-top:10px;
 }  
 .Pop .layui-body{
   justify-content:start;
 }
 .MainForm{
   margin: 0px;
   width:95%;
   margin-top:10px;
 }  
 .w10{
   width:10px;
 } 
 .layui-form-label{
  width:120px;
 }
 </style>